package com.hsxc.cdz.monitor.bean.server.v1_33;

import com.hsxc.cdz.base.util.BytesUtil;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.ReferenceCountUtil;

/**
 * 
 * @author 刘力文
 * 服务器下发刷卡响应的报文类
 *
 */
public class CardSerMsg extends ServerMessage{
	public static final int length = 12; //报文体长度
	private int chargePort;              //充电口号
	private String cardNum;              //用户卡号
	private int isValid;                 //是否有效
	public int getChargePort() {   
		return chargePort;
	}
	public void setChargePort(int chargePort) {
		this.chargePort = chargePort;
	}
	public String getCardNum() {
		return cardNum;
	}
	public void setCardNum(String cardNum) {
		this.cardNum = cardNum;
	}
	public int getIsValid() {
		return isValid;
	}
	public void setIsValid(int isValid) {
		this.isValid = isValid;
	}
	
	public byte[] getBytesFromMessage(){
		ByteBuf bytes = Unpooled.buffer(length);
		byte[] result;
		byte[] temp;
		
		temp = BytesUtil.intToBytesSeq(this.getChargePort(), 1);
		bytes.writeBytes(temp);
		
		temp = BytesUtil.strToBcdBytes(this.getCardNum(), 10);
		bytes.writeBytes(temp);
		
		temp = BytesUtil.intToBytesSeq(this.getIsValid(), 1);
		bytes.writeBytes(temp);
		
		result = new byte[bytes.readableBytes()];
		bytes.readBytes(result);
		ReferenceCountUtil.release(bytes);
		return result;
	}
}
